package dao;

import java.util.ArrayList;
import java.util.HashMap;

import org.springframework.orm.ibatis.SqlMapClientTemplate;

import util.Utilities;

import dto.AdminDTO;
import dto.CompanyDTO;
import dto.ListMemberPageDTO;
import dto.MemberDTO;
import dto.SaleListDTO;
 

public class MemberDAO {
	private SqlMapClientTemplate sqlMap;
	public MemberDAO(SqlMapClientTemplate sqlMap){
		this.sqlMap = sqlMap;
	}
	//동으로 주소검색
	public ArrayList addressSearch(String dong) {
		
		return (ArrayList) sqlMap.queryForList("member.addressSearch",dong);
	}
	//회원검색
	public MemberDTO selectMemberById(String id) {
		return (MemberDTO) sqlMap.queryForObject("member.selectMemberByid", id);
	}
	//기업검색
	public CompanyDTO selectCompanyById(String id) {
		return (CompanyDTO) sqlMap.queryForObject("member.selectCompanyByid", id);
	}
	//관리자검색
	public AdminDTO selectAdminById(String id) {
		return (AdminDTO) sqlMap.queryForObject("member.selectAdminByid", id);
	}
	//회원삭제
	public int deleteMemberById(String id) {
		return sqlMap.delete("member.deleteMemberByid", id);
	}
	//기업삭제
	public int deleteCompanyById(String id) {
		return sqlMap.delete("member.deleteCompanyByid", id);
	}
	//관리자 삭제
	public int deleteAdminById(String id) {
		return sqlMap.delete("member.deleteAdminByid", id);
	}
	//회원등록
	public void registerMember(MemberDTO mdto) {
		
		 sqlMap.insert("member.registerMember", mdto);
		 
	}
	//기업등록
	public void registerCompany(CompanyDTO cdto) {
		 sqlMap.insert("member.registerCompany", cdto);
		
	}
	//회원수정
	public void modifyMember(MemberDTO mdto) {
		sqlMap.update("member.modifyMember", mdto);
		
	}
	//기업수정
	public void modifyCompany(CompanyDTO cdto) {
		sqlMap.update("member.modifyCompany", cdto);
		
	}
	//관리자수정
	public void modifyAdmin(AdminDTO adto) {
		sqlMap.update("member.modifyAdmin", adto);
		
	}
	//모든회원조회
	public ArrayList<MemberDTO> getAllMember() {
		return (ArrayList<MemberDTO>) sqlMap.queryForList("member.getAllMember");
	}
	//모든기업조회
	public ArrayList<CompanyDTO> getAllCompany() {
		return (ArrayList<CompanyDTO>) sqlMap.queryForList("member.getAllCompany");
		
	}
	//관리자-회원강제탈퇴
	public void adminMemberDelete(MemberDTO mdto) {
		sqlMap.update("member.adminMemberDelete", mdto);
	}
	//관리자-기업강제탈퇴
	public void adminCompanyDelete(CompanyDTO cdto) {
		sqlMap.update("member.adminCompanyDelete", cdto);
	}
	//회원id중복체크
	public String memberIdSearchResult(MemberDTO mdto) {
	 
		return (String) sqlMap.queryForObject("member.memberIdSearchResult",mdto);
	}
	//회원password중복체크
	public String memberPasswordSearchResult(MemberDTO mdto) {
		return (String) sqlMap.queryForObject("member.memberPasswordSearchResult", mdto);
	}
	//기업id중복체크
	public String companyIdSearchResult(CompanyDTO cdto) {
		return (String) sqlMap.queryForObject("member.companyIdSearchResult", cdto);
	}
	//기업password중복체크
	public String companyPasswordSearchResult(CompanyDTO cdto) {
		return (String) sqlMap.queryForObject("member.companyPasswordSearchResult",cdto);
	}
	//관리자 id중복체크
	public String adminIdSearchResult(AdminDTO adto) {
		return (String) sqlMap.queryForObject("member.adminIdSearchResult", adto);
	}
	//관리자password중복체크
	public String adminPasswordSearchResult(AdminDTO adto) {
		return (String) sqlMap.queryForObject("member.adminPasswordSearchResult", adto);
	}
	//관리자-회원탈퇴취소
	public void adminMemberReceive(MemberDTO mdto) {
		sqlMap.update("member.adminMemberReceive", mdto);
		
	}
	//관리자-기업탈퇴취소
	public void adminCompanyReceive(CompanyDTO cdto) {
		sqlMap.update("member.adminCompanyReceive", cdto);
		
	}
	//paging

	public ArrayList<MemberDTO> selectMemberListByPaging(int page) {
		  
		HashMap map = new HashMap();
		map.put("page", page);
		map.put("perPage", Utilities.CONTENT_PER_PAGE);
		return (ArrayList<MemberDTO>) sqlMap.queryForList("member.selectMemberListByPage",map);
	}
	public int selectMemberTotalContent() {
		return (Integer) sqlMap.queryForObject("member.selectMemberTotalContent");
	}
	public ArrayList<CompanyDTO> selectCompanyListByPaging(int page) {
		HashMap map = new HashMap();
		map.put("page", page);
		map.put("perPage", Utilities.CONTENT_PER_PAGE);
		return (ArrayList<CompanyDTO>) sqlMap.queryForList("member.selectCompanyListByPage",map);
	}
	public int selectCompanyTotalContent() {
		return (Integer) sqlMap.queryForObject("member.selectCompanyTotalContent");
	}
	public void updateCredit(HashMap<String, String> map) {
		sqlMap.update("member.updateCredit", map);
		
	}
	public void updateCreditCompany(HashMap<String, String> map) {
		sqlMap.update("member.updateCreditCompany", map);
		
	}
	public void memberPointAdd(HashMap<String, String> map) {
		sqlMap.update("member.memberPointAdd", map);
		
	}
	public void companyPointAdd(HashMap<String, String> map) {
		sqlMap.update("member.companyPointAdd",map);
	}
	 

}
